const request = require("../utils/request");
const { getFormatError } = require("../utils");

const AssetsProxyService = {
  async getFile(data) {
    try {
      const headers = {};
      if (data.platform === "douban" || !data.platform) {
        headers.referer = "https://movie.douban.com/tv/";
      }
      const res = await request({
        url: data.url,
        responseType: "arraybuffer",
        headers,
      });
      return Buffer.from(res.data, "binary");
    } catch (err) {
      throw getFormatError(err, { message: "文件获取失败" });
    }
  },
};

module.exports = AssetsProxyService;
